package me.aip.mov.controller;


import me.aip.mov.annotation.GlobalResult;
import me.aip.mov.annotation.PassToken;
import me.aip.mov.constant.Constant;
import me.aip.mov.minio.FileTypeEnum;
import me.aip.mov.minio.MinIoUtil;
import me.aip.mov.response.ResponseResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.UUID;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author aip9105
 * @since 2022-02-08
 */
@RestController
@RequestMapping("/file")
public class FileController {

    @Resource
    private MinIoUtil minIoUtil;

    @PostMapping("uploadAvatar")
    @PassToken
    public String uploadAvatar(MultipartFile file) throws IOException {

        String fileName = file.getOriginalFilename();
        String url = minIoUtil.putAndReturnUrl(file.getInputStream(), FileTypeEnum.IMG, file.getContentType(), fileName);
        return url;
    }

    @PostMapping("uploadAdvise")
    @PassToken
    public String uploadAdvise(MultipartFile file) throws IOException {
        String fileName = file.getOriginalFilename();
        String url = minIoUtil.putAndReturnUrl(file.getInputStream(), FileTypeEnum.IMG, file.getContentType(), fileName);
        return url;
    }
    @PostMapping("uploadVideo")
    @PassToken
    public String uploadVideo(MultipartFile file) throws IOException {
        String fileName = file.getOriginalFilename();
        String url = minIoUtil.putAndReturnUrl(file.getInputStream(), FileTypeEnum.VIDEO, file.getContentType(), fileName);
        return url;
    }
    @PostMapping("uploadVoice")
    @PassToken
    public String uploadVoice(MultipartFile file) throws IOException {
        String fileName = file.getOriginalFilename();
        String url = minIoUtil.putAndReturnUrl(file.getInputStream(), FileTypeEnum.VOICE, file.getContentType(), fileName);
        return url;
    }
    @PostMapping("uploadImages")
    @PassToken
    public String uploadImages(MultipartFile file) throws IOException {
        String fileName = file.getOriginalFilename();
        String url = minIoUtil.putAndReturnUrl(file.getInputStream(), FileTypeEnum.IMG, file.getContentType(), fileName);
        return url;
    }
}
